#! /usr/bin/env python
# -*- coding: utf-8 -*-


import sys
import logging
import traceback


logging.basicConfig(
    stream=sys.stdout,
    level="INFO",
    format='[%(asctime)s] [%(name)s] [%(process)d] [%(levelname)s] %(message)s',
)


def _setup_exception_hook():
    # 打印异常时打印时间

    def exception_hook(type, value, tb):
        print(type, value, tb)
        error_stack = ''.join(traceback.format_exception(type, value, tb))
        logging.error("program exception: %s\n%s", value, error_stack)

    sys.excepthook = exception_hook


def _setup_exception_hook2():
    # 打印异常时打印时间

    def exception_hook(type, value, tb):
        print(type, value, tb)
        logging.error(''.join(traceback.format_exception(type, value, tb)))

    sys.excepthook = exception_hook


_setup_exception_hook()


1 / 0

